package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.common.utils.ThreadLocalUtil;
import com.ayou.eggguard.farm.pojo.Announce;
import com.ayou.eggguard.farm.service.AnnounceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/announce")
public class AnnounceController {

    @Autowired
    private AnnounceService announceService;

    @PostMapping("/add")
    public Result add(@RequestBody Announce announce){
        announceService.add(announce);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        announceService.delete(id);
        return Result.success();
    }

    @PostMapping("/updateAnnounce")
    public Result updateAnnounce(@RequestBody Announce announce){
        announceService.updateAnnounce(announce);
        return Result.success();
    }

    @GetMapping("/getAnnounceByPage")
    public Result<PageBean<Announce>> getAnnounceByPage(Integer pageNum,
                                                  Integer pageSize,
                                                  @RequestParam(required = false) String title){
        PageBean<Announce> pb=announceService.getAnnounceByPage(pageNum,pageSize,title);
        return Result.success(pb);
    }

    @GetMapping("/updateAnnounceStatus")
    public Result updateAnnounceStatus(Integer id){
        announceService.updateAnnounceStatus(id);
        return Result.success();
    }

}
